import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "./ObjCreate";
import { BaseItem } from "./BaseItem";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { NumInput } from "./NumInput";
import { ItemData } from "../../resource/info/ItemData";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../resource/ColorConfig";
type int = number;
//class SelectNumWindow
    
    export  class SelectNumWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.init();
            return;
        }

        public get btnOK(): GButton
        {
            return this._okBtn;
        }

        public init(): void
        {
            this.setSize(295, 175);
            this.titleHeight = 28;
            this.title = Language.getString(69900);
            this._bg = ObjCreate.createBg(18, 40, 258, 125, this);
            this._baseItem = new BaseItem();
            this._baseItem.width = 38;
            this._baseItem.height = 38;
            this._baseItem.move(32, 80);
            this.addChild(this._baseItem);
            this._tipTxt = ObjCreate.createTextField("", 20, 45, 248, 20, this, GlobalStyle.textFormat6);
            this._tipTxt.htmlText = Language.getString(57259);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.wordWrap = true;
            this._tipTxt.multiline = true;
            this._nameTxt = ObjCreate.createTextField("", 90, 80, 170, 20, this);
            this._numLabel = ObjCreate.createTextField(Language.getString(71548), 90, 100, 170, 20, this);
            this._numStepper = new NumInput();
            this._numStepper.maxNum = 99;
            this._numStepper.x = 150;
            this._numStepper.y = 100;
            this.addChild(this._numStepper);
            this._okBtn = new GButton();
            this._okBtn.label = Language.getString(57239);
            this._okBtn.name = "SaleButton";
            this._okBtn.styleName = "Button";
            this._okBtn.setSize(48, 27);
            this._okBtn.move(65, 130);
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkBtnClickHandler);
            this.addChild(this._okBtn);
            this._cancelBtn = new GButton();
            this._cancelBtn.label = Language.getString(57240);
            this._cancelBtn.name = "SaleButton";
            this._cancelBtn.styleName = "Button";
            this._cancelBtn.setSize(48, 27);
            this._cancelBtn.move(160, 130);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            this.addChild(this._cancelBtn);
            return;
        }

        public updateByItemData(arg1: ItemData, arg2: Function=null): void
        {
            this._callBack = arg2;
            if (arg1) 
            {
                this._itemData = arg1;
                this._nameTxt.htmlText = HTMLUtil.addColor(arg1.itemInfo.item.name, ColorConfig.instance.getItemColor(arg1.itemInfo.item.color).color);
                this._numStepper.maxNum = arg1.itemAmount;
                this._baseItem.itemData = arg1;
                this._baseItem.amount = -1;
                this.reset(false);
            }
            return;
        }

        /* internal  */reset(arg1: Boolean): void
        {
            if (arg1) 
            {
                this.height = 175;
                this._bg.height = 125;
                this._baseItem.y = 80;
                this._nameTxt.y = 80;
                this._tipTxt.visible = true;
                this._numLabel.y = 100;
                this._numStepper.y = 100;
                this._okBtn.y = 130;
                this._cancelBtn.y = 130;
            }
            else 
            {
                this.height = 145;
                this._bg.height = 95;
                this._baseItem.y = 50;
                this._nameTxt.y = 50;
                this._tipTxt.visible = false;
                this._numLabel.y = 70;
                this._numStepper.y = 70;
                this._okBtn.y = 100;
                this._cancelBtn.y = 100;
            }
            return;
        }

        /* internal  */onOkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=flash.utils.getTimer();
            if (loc1 - this.lastTime < 1000) 
            {
                return;
            }
            this.lastTime = loc1;
            if (this._itemData) 
            {
                if (this._callBack != null) 
                {
                    this._callBack(this._itemData, this._numStepper.currentNum);
                }
            }
            hide();
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            hide();
            return;
        }

        public set maxAmount(arg1: int)
        {
            this._numStepper.maxNum = arg1;
            this._maxAmount = arg1;
            return;
        }

        public set curAmount(arg1: int)
        {
            this._numStepper.currentNum = arg1;
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_titleTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_numStepper: NumInput;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_numLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_callBack: Function;

        /* internal */ /* var */_maxAmount: int;

        /* internal */ /* var */lastTime: int;
    }
